#ifndef COMMONFUNCTION_H
#define COMMONFUNCTION_H
#include "ettadatastruct.h"
#include "constants.h"

#include <QString>

//get current datetime(second) "yyyy-MM-dd hh:mm:ss"
QString currentDateTime();

//get current datetime(millisecond) "yyyy-MM-dd hh:mm:ss.zzz"
QString currentDateTimeMS();

//convert "yyyy-MM-dd hh:mm:ss.zzz" to "yyyy-MM-dd hh:mm:ssz"
QString convertMillSec2Sec(QString currDT);
Role initRole();

bool createDir(QString path);

void setWidgetCenter(QWidget *w);


bool openTextByIODevice(const QString FileName,QString line);

//get jpg,png picture absolute path
QStringList getPicFileNameList(const QString & path);

void log_info(LogType logtype, QString code ,QString detail);

bool checkIPValid(const QString & add);

QString generateFileName(const QString & dir, const QString & prefix, const QString & suffix);

//return diff = dt2 - dt1 (second)
qint64 timeDiffSecond(QDateTime dt1, QDateTime dt2);

//contain upper, lower and digit. true: valid, false:invalid.
bool checkPwValid(const QString & pw);

//check if password is equal to default
bool checkPwSimple(const QString & pw);

//make random number
int random(int min, int max);

bool doubleEquals(double d1, double d2);
bool doubleGreater(double d1, double d2);

QString doubleToString(double d, int n);

quint64 predictRuntimes(double liquidVolume, double flowRate);

#endif // COMMONFUNCTION_H
